package com.hw.util;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 国兴越
 * @version 1.0
 * Create by
 */
@Data
public class R implements Serializable {


    private String message;
    private boolean flag;
    private int code;
    private Map<String ,Object> data =new HashMap<>(16);

    public R message(String message) {
        this.message = message;
        return this;
    }

    public R flag(boolean flag) {
        this.flag = flag;
        return this;
    }

    public R code(int code) {
        this.code = code;
        return this;
    }

    public R data(Map<String, Object> data) {
        this.data.putAll(data);
        return this;
    }
    public R data(String key,Object value) {
        this.data.put(key,value);
        return this;
    }

    public static R ok(){

        R r = new R();
        r.message="操作成功";
        r.code=CodeStatus.SUCCESS;
        r.flag=true;
        return r;

    }

    public static R error(){
        R r = new R();
        r.message="操作失败";
        r.code=CodeStatus.ERROR;
        r.flag=false;
        return r;
    }

}
